package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YyPatient;
import com.ruoyi.system.service.IYyPatientService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 患者Controller
 * 
 * @author ruoyi
 * @date 2025-03-24
 */
@Controller
@RequestMapping("/system/patient")
public class YyPatientController extends BaseController
{
    private String prefix = "system/patient";

    @Autowired
    private IYyPatientService yyPatientService;

    @RequiresPermissions("system:patient:view")
    @GetMapping()
    public String patient()
    {
        return prefix + "/patient";
    }

    /**
     * 查询患者列表
     */
    @RequiresPermissions("system:patient:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YyPatient yyPatient)
    {
        startPage();
        List<YyPatient> list = yyPatientService.selectYyPatientList(yyPatient);
        return getDataTable(list);
    }

    /**
     * 导出患者列表
     */
    @RequiresPermissions("system:patient:export")
    @Log(title = "患者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YyPatient yyPatient)
    {
        List<YyPatient> list = yyPatientService.selectYyPatientList(yyPatient);
        ExcelUtil<YyPatient> util = new ExcelUtil<YyPatient>(YyPatient.class);
        return util.exportExcel(list, "患者数据");
    }

    /**
     * 新增患者
     */
    @RequiresPermissions("system:patient:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存患者
     */
    @RequiresPermissions("system:patient:add")
    @Log(title = "患者", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YyPatient yyPatient)
    {
        return toAjax(yyPatientService.insertYyPatient(yyPatient));
    }

    /**
     * 修改患者
     */
    @RequiresPermissions("system:patient:edit")
    @GetMapping("/edit/{patientId}")
    public String edit(@PathVariable("patientId") Long patientId, ModelMap mmap)
    {
        YyPatient yyPatient = yyPatientService.selectYyPatientByPatientId(patientId);
        mmap.put("yyPatient", yyPatient);
        return prefix + "/edit";
    }

    /**
     * 修改保存患者
     */
    @RequiresPermissions("system:patient:edit")
    @Log(title = "患者", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YyPatient yyPatient)
    {
        return toAjax(yyPatientService.updateYyPatient(yyPatient));
    }

    /**
     * 删除患者
     */
    @RequiresPermissions("system:patient:remove")
    @Log(title = "患者", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yyPatientService.deleteYyPatientByPatientIds(ids));
    }
}
